using System;

namespace SMS.SMPPClient.PDU.Incoming
{
    /// <summary>
    /// Response PDU for the data_sm command.
    /// </summary>
    public class SMPPDataSMResponse : SMPPSubmitSMResponse
    {

        /// <summary>
        /// Enumerates the delivery failure types.
        /// </summary>
        public enum DeliveryFailureType : byte
        {
            DestinationUnavailable = 0x00,
            DestinationAddressInvalid = 0x01,
            PermanentNetworkError = 0x02,
            TemporaryNetworkError = 0x03
        }

        /// <summary>
        /// Indicates the reason for delivery failure.
        /// </summary>
        public DeliveryFailureType DeliveryFailureReason
        {
            get
            {
                return (DeliveryFailureType)Enum.Parse(typeof(DeliveryFailureType),
                    Enum.GetName(typeof(DeliveryFailureType),
                    tlvTable.GetOptionalParamBytes((ushort)
                    PDU.OptionalParamCodes.delivery_failure_reason)[0]));
            }

        }

        /// <summary>
        /// Error code specific to a wireless network.  See SMPP spec section
        /// 5.3.2.31 for details.
        /// </summary>
        public string NetworkErrorCode
        {
            get
            {
                return tlvTable.GetOptionalParamString((ushort)
                    PDU.OptionalParamCodes.network_error_code);
            }
        }

        /// <summary>
        /// Text (ASCII) giving additional info on the meaning of the response.
        /// </summary>
        public string AdditionalStatusInfoText
        {
            get
            {
                return tlvTable.GetOptionalParamString((ushort)
                    PDU.OptionalParamCodes.additional_status_info_text);
            }
        }

        /// <summary>
        /// Indicates whether the Delivery Pending Flag was set.
        /// </summary>
        public DPFResultType DPFResult
        {
            get
            {
                return (DPFResultType)Enum.Parse(typeof(DPFResultType),
                    Enum.GetName(typeof(DPFResultType),
                    tlvTable.GetOptionalParamBytes((ushort)
                    PDU.OptionalParamCodes.dpf_result)[0]));
            }
        }

        /// <summary>
        /// Creates a data_sm_resp PDU.
        /// </summary>
        /// <param name="response">The byte response from the SMSC.</param>
        public SMPPDataSMResponse(byte[] response)
            : base(response)
        {
            base.DecodeSMSCResponse();
        }
    }
}
